package com.amsp.oa.oademo.controller;

import com.amsp.oa.oademo.common.R;
import com.amsp.oa.oademo.service.PersonnelChangeService;
import com.amsp.oa.oademo.vo.PersonnelChangeVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@Api(tags = "人事异动管理")
@RestController
@RequestMapping("/api/personnel-change")
public class PersonnelChangeController {

    @Resource
    private PersonnelChangeService personnelChangeService;

    @ApiOperation("分页查询")
    @GetMapping("/page")
    public R page(
            @RequestParam(defaultValue = "1") Integer current,
            @RequestParam(defaultValue = "10") Integer size,
            @ApiParam("月份") @RequestParam(required = false) String monthValue,
            @ApiParam("文号") @RequestParam(required = false) String docNumber,
            @ApiParam("审核人") @RequestParam(required = false) String reviewer,
            @ApiParam("核准人") @RequestParam(required = false) String approver) {
        return R.ok(personnelChangeService.page(current, size, monthValue, docNumber, reviewer, approver));
    }

    @ApiOperation("根据ID查询")
    @GetMapping("/{id}")
    public R getById(@PathVariable Long id) {
        return R.ok(personnelChangeService.getById(id));
    }

    @ApiOperation("保存或更新")
    @PostMapping("/save")
    public R saveOrUpdate(@RequestBody PersonnelChangeVO personnelChangeVO) {
        personnelChangeService.saveOrUpdate(personnelChangeVO);
        return R.ok();
    }

    @ApiOperation("删除")
    @DeleteMapping("/{id}")
    public R delete(@PathVariable Long id) {
        personnelChangeService.deleteById(id);
        return R.ok();
    }
}